//
//  DDCartSectionHeader.m
//  Dingdong
//
//  Created by 程强 on 16/11/15.
//  Copyright © 2016年 程强. All rights reserved.
//

#import "DDCartSectionHeader.h"

@interface DDCartSectionHeader()
@property (strong, nonatomic) KKLabel *titleLbl;
@property (strong, nonatomic) KKLabel *activityLbl;
@end

@implementation DDCartSectionHeader

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_selectBtn setBackgroundImage:LoadImage(@"cart_unselect") forState:UIControlStateNormal];
        [_selectBtn setBackgroundImage:LoadImage(@"common_select") forState:UIControlStateSelected];
        [_selectBtn addTarget:self action:@selector(selectHeaderAll:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_selectBtn];
        [_selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.left.equalTo(self).offset(15);
            make.width.height.equalTo(@20);
        }];
        
        self.titleLbl = [[KKLabel alloc]initWithBlock:^(KKLabel *lbl) {
            lbl.laText(@"",[UIColor blackColor],[UIFont systemFontOfSize:15.0],NSTextAlignmentLeft);
        }];
        [self addSubview:_titleLbl];
        [_titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.left.equalTo(_selectBtn.mas_right).offset(15);
            make.width.equalTo(@100);
            make.height.equalTo(@30);
        }];
        
        self.activityLbl = [[KKLabel alloc]initWithBlock:^(KKLabel *lbl) {
            lbl.laText(@"",RGBColor(255, 80, 80),[UIFont systemFontOfSize:15.0],NSTextAlignmentLeft);
        }];
        [self addSubview:_activityLbl];
        [_activityLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(_titleLbl);
            make.left.equalTo(_titleLbl.mas_right).offset(10);
            make.right.equalTo(self).offset(-15);
            make.height.equalTo(@30);
        }];
        
        KKView *line = [[KKView alloc]initWithBlock:^(KKView *view) {
            
        }];
        line.backgroundColor = RGBColor(237, 237, 237);
        [self addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self);
            make.height.equalTo(@1);
            make.bottom.equalTo(self.mas_bottom).offset(1.0);
        }];
    }
    return self;
}
- (void)selectHeaderAll:(UIButton *)btn
{
    if (self.selectBlock) {
        self.selectBlock(btn.selected);
    }
}
- (void)selectSection:(SectionSelectAll)block
{
    self.selectBlock = block;
}
- (void)setStoreName:(NSString *)storeName
{
    _storeName = storeName;
    _titleLbl.text = storeName;
    
    CGFloat width = [ToolKit widthWithFont:[UIFont systemFontOfSize:15.0] height:30 text:storeName];
    width+=10;
    if (width>ScreenWidth*0.6) {
        width = ScreenWidth*0.6;
    }
    [_titleLbl mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(width));
    }];
}
- (void)setActivityName:(NSString *)activityName
{
    _activityName = activityName;
    _activityLbl.text = activityName;
}
@end
